#include <stdio.h>
#include <netdb.h>

int main (int argc, char* argv[])
{
    struct servent *sptr;
    char *service, *protocol;

    if (argc < 3) {
        printf("The arguments is not enough!\n");
        return -1;
    }

    service = argv[1];
    protocol = argv[2];
    sptr = getservbyname(service, protocol);
   if (sptr) {
        printf("the port of service %s using %s protocol is %d.\n", sptr->s_name, protocol, ntohs(sptr->s_port));  //将网络字节顺序的端口值转换成主机顺序
    } else {
        printf("Error!\n");
    }

    return 0;
}
